﻿<%@ Page Title="Subscriber" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="crm_subscribers.aspx.cs" Inherits="Sami_SMS_CRM_UI.crm_subscribers" %>

<%@ Register Src="UserControl/ucPaging.ascx" TagName="ucPaging" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CssContent" runat="server">
    <style type="text/css">
        .box-content p{margin:2px 0 0 5px;}
        .box-content p span{display: inline-block; width: 110px;}
        .detail{color: #555555; text-decoration:none;}
        .detail:hover{text-decoration:underline;}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            RegisterDialog();
            DatePicker("txtDateOfBirth");
        });

        function Enabled(obj, subscriber, serviceId){
            var enable = ($.trim($(obj).html()).toLowerCase() == "true" ? true : false);
            $.ajax({
                type: "POST",
                contentType: "application/json; charset = utf-8",
                dataType: "json",
                url: "crm_subscribers.aspx/EnableServiceSubscriber",
                data: "{'subscriber': " + JSON.stringify(subscriber) +", 'serviceId': " +  JSON.stringify(serviceId) + ", 'enable': " + JSON.stringify(!enable) +"}",
                success: function(data){
                    if(data.d == true){
                        $(obj).html((!enable).toString().replace(/\b[a-z]/g, function(letter) {
                            return letter.toUpperCase();
                        }));
                    }
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="box">
        <div class="box-title">
            Searching
        </div>
        <div class="box-content ui-widget-content">
            <p>
                <span>Subscriber</span>
                <asp:TextBox ID="txtSubscriber" runat="server" />
            </p>
            <p>
                <span>Enable</span>
                <asp:DropDownList ID="ddlEnable" runat="server">
                    <asp:ListItem Value="">---</asp:ListItem>
                    <asp:ListItem Value="true">True</asp:ListItem>
                    <asp:ListItem Value="false">False</asp:ListItem>
                </asp:DropDownList>
            </p>
            <p style="text-align:center">
                <asp:Button ID="btnSearching" runat="server" Text="Search" CssClass="ui-button" 
                    onclick="btnSearching_Click" />
            </p>
        </div>
    </div>
    <div class="box">
        <div class="box-title clearfix">
            <div class="fl">
                List of Subscriber
            </div>
            <div class="fr">
                <asp:ImageButton ID="btnAddNew" runat="server" ImageUrl="~/img/icons/ws/ic_plus.png"
                    ToolTip="Add New" OnClick="btnAddNew_Click" />
            </div>
        </div>
        <div class="box-content">
            <div class="clearfix" style="height: 32px">
                <div class="fl">
                    Show
                    <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="10">10</asp:ListItem>
                        <asp:ListItem Value="20">20</asp:ListItem>
                        <asp:ListItem Value="50" Selected="True">50</asp:ListItem>
                        <asp:ListItem Value="100">100</asp:ListItem>
                        <asp:ListItem Value="150">150</asp:ListItem>
                        <asp:ListItem Value="200">200</asp:ListItem>
                    </asp:DropDownList> /
                    <asp:Literal ID="ltrTotalRow" runat="server" Text="0" />
                    entries
                </div>
                <div class="fr">
                    <uc1:ucPaging ID="pagingtop" runat="server" />
                </div>
            </div>
            <div class="clearfix">
                <table class="table" style="width: 100%;">
                    <thead>
                        <tr>
                            <th style="width: 35px">
                                No
                            </th>
                            <th style="width: 145px">
                                Subscriber
                            </th>
                            <th style="width: 180px">
                                Full Name
                            </th>
                            <th style="width: 160px">
                                Date of birth
                            </th>
                            <th>
                                Address
                            </th>
                            <th>
                                Description
                            </th>
                            <th style="width: 50px">
                                Enable
                            </th>
                            <th style="width:80px;">Control</th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater ID="rptTable" runat="server" onitemcommand="rptTable_ItemCommand">
                            <ItemTemplate>
                                <tr>
                                    <td style="text-align: center">
                                        <%#(Container.ItemIndex +1) + (pagingtop.CurrentPage - 1) * pagingtop.PageSize %>
                                    </td>
                                    <td>
                                        <asp:LinkButton Text='<%#Eval("subscriber")%>' CommandName="ViewDetail" CommandArgument='<%#Eval("subscriber")%>' runat="server" CssClass="detail" />
                                    </td>
                                    <td>
                                        <%#Eval("full_name")%>
                                    </td>
                                    <td>
                                        <%#Eval("date_of_birth")%>
                                    </td>
                                    <td>
                                        <%#Eval("address")%>
                                    </td>
                                    <td>
                                        <%#Eval("note")%>
                                    </td>
                                    <td>
                                        <%#Eval("enabled")%>
                                    </td>
                                    <td style="text-align:center">
                                        <asp:LinkButton Text="Edit" runat="server" CommandName="Edited"
                                            CommandArgument='<%#Eval("subscriber")%>' />
                                            &nbsp;
                                        <asp:LinkButton Text="Delete" runat="server" CommandName="Deleted"
                                            CommandArgument='<%#Eval("subscriber")%>' OnClientClick="return confirm('Are you sure delete?');" />
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tbody>
                </table>
                <div class="fr">
                    <uc1:ucPaging ID="pagingbottom" runat="server" />
                </div>
            </div>
        </div>
    </div>

            <div class="dialog-form" id="dialog1" style="margin: auto; width: 480px;" title="CRM Subscriber">
        <div>
            <asp:HiddenField ID="hdfAction" runat="server" />
            <asp:HiddenField ID="hdfId" runat="server" />
            <p>
                <span>Subscriber</span>
                <asp:TextBox ID="txtSubs" runat="server" />
            </p>
            <p>
                <span>Full Name</span>
                <asp:TextBox ID="txtFullName" runat="server" />
            </p>
            <p>
                <span>Gender</span>
                <asp:DropDownList ID="ddlGender" runat="server">
                    <asp:ListItem Value="true">Male</asp:ListItem>
                    <asp:ListItem Value="false">FeMale</asp:ListItem>
                </asp:DropDownList>
            </p>
            <p>
                <span>Date of birth</span>
                <asp:TextBox ID="txtDateOfBirth" runat="server" />
            </p>
            <p>
                <span>Address</span>
                <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" />
            </p>
            <p>
                <span>Description</span>
                <asp:TextBox ID="txtNote" runat="server" TextMode="MultiLine" />
            </p>
            <p>
                <span>Enabled</span>
                <asp:DropDownList ID="ddlEnabled" runat="server">
                    <asp:ListItem Value="true">True</asp:ListItem>
                    <asp:ListItem Value="false">False</asp:ListItem>
                </asp:DropDownList>
            </p>
            <div style="text-align: right; margin-top: 5px; padding-top: 5px; border-top: 1px solid #C3C3C3;">
                <asp:Button ID="btnOK" runat="server" Text="OK" CssClass="ui-button" OnClick="btnOK_Click" />
                <input type="button" value="Cancel" onclick='$("#dialog1").dialog("close");'
                    class="ui-button" />
            </div>
        </div>
    </div>
    <div class="dialog-form" id="dialog2" style="margin: auto; width: 1000px;" title="Subscriber">
        <table class="table" style="width:100%">
            <thead>
                <tr>
                    <th>Subscriber</th>
                    <th>Service</th>
                    <th>Used counter</th>
                    <th>Vasp num</th>
                    <th>Lastest used</th>
                    <th>Advertisement previous sent</th>
                    <th>Advertisement lastest sent</th>
                    <th>Advertisement counter</th>
                    <th>Measurement</th>
                    <th>Enabled</th>
                </tr>
            </thead>
            <tbody>
                <asp:Repeater ID="rptSubsService" runat="server" EnableViewState="false">
                    <ItemTemplate>
                        <tr>
                            <td><%#Eval("subscriber")%></td>
                            <td title="service_id: <%#Eval("service_id")%>; service_name: <%#Eval("service_name")%>">
                                <%#Eval("service_name")%>
                            </td>
                            <td><%#Eval("used_counter")%></td>
                            <td><%#Eval("vasp_num")%></td>
                            <td><%#Eval("lastest_used")%></td>
                            <td><%#Eval("advertisement_previous_sent")%></td>
                            <td><%#Eval("advertisement_lastest_sent")%></td>
                            <td><%#Eval("advertisement_counter")%></td>
                            <td><%#Eval("measurement")%></td>
                            <td style="text-align:center">
                                <a href="javascript:void();" onclick='javascript:Enabled(this,"<%#Eval("subscriber")%>",<%#Eval("service_id")%> ); return false;'><%#Eval("enabled")%></a>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </tbody>
        </table>
    </div>
    <input type="hidden" id="formId" value="crm_subscriber" />
</asp:Content>
